<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.List, com.petcommunity.model.VaccineRecord" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    List<VaccineRecord> records = (List<VaccineRecord>) request.getAttribute("records");
%>
<%
    String role = (String) session.getAttribute("role");
%>
<html>
<head>
    <title>疫苗记录管理</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="stylesheet" href="css/management.css">
</head>
<body>
    <!-- 装饰性爪印 -->
    <i class="fas fa-paw decorative-paws paw-1"></i>
    <i class="fas fa-paw decorative-paws paw-2"></i>
    <i class="fas fa-paw decorative-paws paw-3"></i>
    <i class="fas fa-paw decorative-paws paw-4"></i>

    <div class="page-container">
        <div class="main-container">
            <!-- 页面头部 -->
            <div class="page-header">
                <div class="header-content">
                    <div class="header-icon">
                        <i class="fas fa-syringe"></i>
                    </div>
                    <h1 class="page-title">疫苗记录管理</h1>
                    <p class="page-subtitle">为宠物健康筑起坚实防线</p>
                </div>
            </div>

            <div class="content-wrapper">
                <!-- 添加疫苗记录表单 -->
                <c:if test="${role == 'admin'}">
                    <div class="form-section">
                        <div class="section-header">
                            <div class="section-title">
                                <i class="fas fa-plus section-icon"></i>
                                添加疫苗记录
                            </div>
                        </div>
                        <form method="post" action="vaccines" class="add-form">
                            <div class="form-row">
                                <div class="form-group">
                                    <label>
                                        <i class="fas fa-paw"></i>
                                        宠物ID
                                    </label>
                                    <input type="number" name="petId" required placeholder="请输入宠物ID">
                                </div>
                                <div class="form-group">
                                    <label>
                                        <i class="fas fa-vial"></i>
                                        疫苗名称
                                    </label>
                                    <input type="text" name="vaccineName" required placeholder="请输入疫苗名称">
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-group">
                                    <label>
                                        <i class="fas fa-calendar-check"></i>
                                        接种日期
                                    </label>
                                    <input type="date" name="vaccinationDate" required>
                                </div>
                                <div class="form-group">
                                    <label>
                                        <i class="fas fa-calendar-plus"></i>
                                        下次应接种日期
                                    </label>
                                    <input type="date" name="nextDueDate" required>
                                </div>
                            </div>
                            <div class="form-actions">
                                <button type="submit" class="submit-btn">
                                    <i class="fas fa-plus btn-icon"></i>
                                    添加记录
                                </button>
                            </div>
                        </form>
                    </div>
                </c:if>

                <!-- 疫苗记录列表 -->
                <div class="table-section">
                    <div class="section-header">
                        <div class="section-title">
                            <i class="fas fa-list section-icon"></i>
                            疫苗记录列表
                        </div>
                        <div class="table-info">
                            <span class="record-count">
                                <c:choose>
                                    <c:when test="${not empty records}">
                                        ${records.size()} 条记录
                                    </c:when>
                                    <c:otherwise>
                                        0 条记录
                                    </c:otherwise>
                                </c:choose>
                            </span>
                        </div>
                    </div>

                    <div class="table-container">
                        <c:choose>
                            <c:when test="${not empty records}">
                                <table class="data-table">
                                    <thead>
                                        <tr>
                                            <th>
                                                <div class="th-content">
                                                    <i class="fas fa-hashtag"></i>
                                                    记录ID
                                                </div>
                                            </th>
                                            <th>
                                                <div class="th-content">
                                                    <i class="fas fa-paw"></i>
                                                    宠物ID
                                                </div>
                                            </th>
                                            <th>
                                                <div class="th-content">
                                                    <i class="fas fa-vial"></i>
                                                    疫苗名称
                                                </div>
                                            </th>
                                            <th>
                                                <div class="th-content">
                                                    <i class="fas fa-calendar-check"></i>
                                                    接种日期
                                                </div>
                                            </th>
                                            <th>
                                                <div class="th-content">
                                                    <i class="fas fa-calendar-plus"></i>
                                                    下次接种
                                                </div>
                                            </th>
                                            <c:if test="${role == 'admin'}">
                                                <th>
                                                    <div class="th-content">
                                                        <i class="fas fa-cogs"></i>
                                                        操作
                                                    </div>
                                                </th>
                                            </c:if>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <c:forEach var="v" items="${records}">
                                            <tr>
                                                <td class="id-cell" data-label="记录ID">${v.recordId}</td>
                                                <td data-label="宠物ID">
                                                    <span class="owner-id">${v.petId}</span>
                                                </td>
                                                <td data-label="疫苗名称">
                                                    <div class="vaccine-info">
                                                        <div class="vaccine-icon" style="width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #E8F5E8 0%, #C8E6C9 100%); display: inline-flex; align-items: center; justify-content: center; margin-right: 10px;">
                                                            <i class="fas fa-shield-alt" style="color: #4CAF50; font-size: 0.9rem;"></i>
                                                        </div>
                                                        <span style="font-weight: 500; color: #333;">${v.vaccineName}</span>
                                                    </div>
                                                </td>
                                                <td class="birth-date" data-label="接种日期">${v.vaccinationDate}</td>
                                                <td data-label="下次接种">
                                                    <div class="next-due-date" style="color: #FF6B6B; font-weight: 500; font-family: 'Courier New', monospace;">
                                                        ${v.nextDueDate}
                                                    </div>
                                                </td>
                                                <c:if test="${role == 'admin'}">
                                                <td data-label="操作">
                                                    <div class="action-buttons">
                                                        <button class="edit-btn" onclick="editVaccine(${v.recordId}, ${v.petId}, '${v.vaccineName}', '${v.vaccinationDate}', '${v.nextDueDate}')">
                                                            <i class="fas fa-edit"></i>编辑
                                                        </button>
                                                        <button class="delete-btn" onclick="deleteVaccine(${v.recordId})">
                                                            <i class="fas fa-trash"></i>删除
                                                        </button>
                                                    </div>
                                                </td>
                                            </c:if>
                                            </tr>
                                        </c:forEach>
                                    </tbody>
                                </table>
                            </c:when>
                            <c:otherwise>
                                <div class="empty-state">
                                    <div class="empty-icon">
                                        <i class="fas fa-syringe"></i>
                                    </div>
                                    <h3>暂无疫苗记录</h3>
                                    <p>目前还没有任何疫苗接种记录</p>
                                </div>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>

                <!-- 返回按钮 -->
                <div class="back-section">
                    <a href="dashboard.jsp" class="back-btn">
                        <i class="fas fa-arrow-left"></i>
                        返回首页
                    </a>
                </div>
            </div>
        </div>
    </div>

    <style>
        /* 疫苗信息样式 */
        .vaccine-info {
            display: flex;
            align-items: center;
        }

        /* 日期输入框样式 */
        input[type="date"] {
            width: 100%;
            padding: 15px 20px;
            border: 2px solid #E8E8E8;
            border-radius: 10px;
            font-size: 1rem;
            transition: all 0.3s ease;
            background: white;
            font-family: 'Courier New', monospace;
        }

        input[type="date"]:focus {
            outline: none;
            border-color: #FF6B6B;
            box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
            transform: translateY(-2px);
        }

        /* 数字输入框样式 */
        input[type="number"] {
            width: 100%;
            padding: 15px 20px;
            border: 2px solid #E8E8E8;
            border-radius: 10px;
            font-size: 1rem;
            transition: all 0.3s ease;
            background: white;
        }

        input[type="number"]:focus {
            outline: none;
            border-color: #FF6B6B;
            box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
            transform: translateY(-2px);
        }

        /* 下次接种日期高亮 */
        .next-due-date {
            padding: 6px 12px;
            background: #FFF8F8;
            border-radius: 8px;
            border: 1px solid #FFE4E1;
        }

        /* 移动端优化 */
        @media (max-width: 768px) {
            .vaccine-info {
                flex-direction: column;
                gap: 5px;
                text-align: center;
            }
        }
    </style>
<script>
function editVaccine(id) {
    if (confirm('确定要编辑该疫苗记录吗？')) {
        window.location.href = 'edit?type=vaccine&id=' + id;
    }
}

function deleteVaccine(id) {
    if (confirm('确定要删除该疫苗记录吗？此操作不可恢复！')) {
        window.location.href = 'delete?type=vaccine&id=' + id;
    }
}
</script>

</body>
</html>